import request from "@/utils/request";

/**
 * 获取拣货单列表
 * @param params
 * @returns {Promise<unknown>}
 */
export function getPickingList(params = {}){
  return request({
    url: '/picking/getPickingList',
    params,
  })
}

/**
 * 获取拣货单的详情
 * @param pickingNo
 * @returns {Promise<unknown>}
 */
export function getPickingInfo(pickingNo){
  return request({
    url: `/picking/getPickingInfo/${pickingNo}`,
    timeout: 180000, // 3分钟
  })
}
export function getPickingInfoExcel(params){
  return request({
    url: `/picking/getPickingInfo/${params.pickingNo}`,
    params,
  })
}

/**
 * 保存对应的拣货单
 * @param data
 * @returns {Promise<unknown>}
 */
export function savePickingOrder(data){
  return request({
    url: `/picking/savePickingOrder`,
    data,
    method: 'post',
  })
}

/**
 * 确认拣货
 * @param data
 * @returns {Promise<unknown>}
 */
export function surePicking(data){
  return request({
    url: `/picking/surePicking`,
    method: 'put',
    data
  })
}

/**
 * 批量确认捡货单
 * @param data
 * @returns {Promise | Promise<unknown>}
 */
export function batchSurePicking(data){
  return request({
    url: `/picking/batchSurePicking`,
    method: 'put',
    data,
    handleError: true,
  })
}

/**
 * 打印面单
 * @param data
 * @returns {Promise | Promise<unknown>}
 */
export function batchPickPDF(data){
  return request({
    url:`/picking/batchPickPDF`,
    method: 'post',
    data,
    responseType: "blob", // 需要加上
    isNotJson: true,
    timeout: 60000, // 1分钟
    handleError: true,
  })
}

/**
 *
 * @param params
 * @returns {Promise | Promise<unknown>}
 */
export function getExceptPickingOrder(params = {}){
  return request({
    url: `/picking/getExceptPickingOrder`,
    method: 'get',
    params,
  })
}

export function cancelExceptPicking(id){
  return request({
    url: `/picking/cancelExceptPicking/${id}`,
    method: 'patch',
  })
}

/**
 * 打印面单
 * @param pickingNo
 * @returns {Promise | Promise<unknown>}
 */
export function printPickShipping(pickingNo){
  return request({
    url:`/picking/printPickShipping/${pickingNo}`,
    method: 'get',
    responseType: "blob", // 需要加上
    isNotJson: true,
    timeout: 60000 * 5, // 5分钟
    handleError: true,
  })
}

/**
 * 打印面单(集成物流)
 * @param data
 * @returns {Promise | Promise<unknown>}
 */
export function printLogisticsPickShipping(data){
  return request({
    url:`/picking/printLogisticsPickShipping`,
    method: 'post',
    data,
    responseType: "blob", // 需要加上
    isNotJson: true,
    timeout: 60000 * 5, // 5分钟
    handleError: true,
    handleResponse: true,
  })
}

/**
 * 打印全部面单加入队列
 * @param data
 * @returns {Promise | Promise<unknown>}
 */
export function printAllLogisticsPickShipping(data){
  return request({
    url:`/picking/printAllLogisticsPickShipping`,
    method: 'post',
    data,
    responseType: "blob", // 需要加上
    isNotJson: true,
    timeout: 60000 * 5, // 5分钟
    handleError: true,
    handleResponse: true,
  })
}
/**
 * 打印原始面单
 * @param data
 * @returns {Promise | Promise<unknown>}
 */
export function printOriginalSheet(data){
  return request({
    url:`/picking/printOriginalSheetTwo`,
    method: 'post',
    data,
    responseType: "blob", // 需要加上
    isNotJson: true,
    timeout: 60000 * 5, // 5分钟
    handleError: true,
    handleResponse: true,
  })
}
